def run(params:list[str]):
    from sklearn import datasets,ensemble 
    from sklearn.metrics import accuracy_score, precision_score,recall_score,f1_score
    from sklearn.metrics import mean_squared_error, r2_score

    # 导入必要的库
    import pandas as pd
    from mlxtend.preprocessing import TransactionEncoder
    from mlxtend.frequent_patterns import apriori, fpgrowth

    from ApiBase import apiBase
    try:
        data=apiBase.argv_json(params,1,{"0.1,0.2":"0.1","0.3,0.4":"0.2","0.4,0.5":"0.2","0.6,0.7":"0.1","0.8,0.9":"0.1"})
        #apiBase.log("param1="+str(data))
        X_digits=[]
        y_digits=[]
        for key in data.keys():
            numbers = [float(num) for num in key.split(',')]
            X_digits.append(numbers)
            val=data[key]
            y_digits.append(val)
        
        ### 1.8.1 随机森林分类
        # 加载digits数据集，数据集简单，便于可视化决策树
        #X_digits, y_digits = datasets.load_digits(return_X_y=True)
        #X_digits = [[1,2],[3,4],[5,6],[7,8],[9,10]]
        #y_digits = [0,0,0,1,1]
        #print(X_digits)
        #print(y_digits)
        #X_digits = X_digits / X_digits.max()


        n_samples = len(X_digits)
        sz=int(0.6 * n_samples)
        #训练集和测试集划分
        X_train = X_digits[: sz]  #取前90%的数据作为训练集，其余作为测试集
        y_train = y_digits[: sz]
        X_test = X_digits[sz :]
        y_test = y_digits[sz :]

        #创建模型，RandomForestClassifier分类器
        clf = ensemble.RandomForestClassifier(n_estimators=500, max_depth=10) #n_estimators：弱分类器数量
                                                        #max_depth树的最大深度，还有很多其他参数，此处使用默认值

        #模型训练
        clf.fit(X_train, y_train) #对于分类问题，可以通过简单的多数投票法来确定预测类别

        #模型预测
        y_pred = clf.predict(X_test)

        ##评价指标
        import json
        retdata={}
        # accuracy
        retdata["accuracy_score"]= accuracy_score(y_test,y_pred) #不平衡类别分布的情况下可能会失效
        # precision指标
        retdata["precision_score"]= precision_score(y_test,y_pred,average='macro') #多分类，需要加average参数
        # recall_score指标
        retdata["recall_score" ]= recall_score(y_test,y_pred,average='macro')
        #f1指标
        retdata["f1_score"]= f1_score(y_test,y_pred,average='macro')
        return json.dumps(retdata,ensure_ascii=False)
    except Exception as e:
        return f"function error:{e}"




